`
https://leetcode.cn/problems/1GxJYY/
`

/**
 * @param {number[]} flowers
 * @param {number} cnt
 * @return {number}
 */
var beautifulBouquet = function (flowers, cnt) {
  const n = flowers.length
  let res = 0
  const counter = new Map()
  let left = 0, right = 0

  while (right < n) {
    const n1 = flowers[right++]
    counter.set(n1, (counter.get(n1) || 0) + 1)

    while (counter.get(n1) > cnt) {
      const n2 = flowers[left++]
      counter.set(n2, counter.get(n2) - 1)
    }

    res += right - left
  }

  return res
};